// pages/goods_detail/goods_deail.js
const app = getApp()
var service_common = require("../../service/common.js");
const service = require('../../utils/service.js')
const api = require('../../utils/util.js')
const WxParse = require('../wxParse/wxParse.js')
Page({
  data: {
    goods_id: '',
    userInfo: {},
    goodsInfo: {},
    goodsComment: [], // 评论列表
    page: 1, // 商品评论页数
    num: 1, // 购买数量
    hasMoreComment: true,
    lowPrice: '', // 最低价
    topPrice: '', // 最高价
    lowKillPrice: '', // 最低秒杀价
    topKillPrice: '', // 最高秒杀价
    topMarkPrice: '', // 最高市场价
    lowMarkPrice: '', // 最低市场价
    choicOption: '', // 选中的规格
    choicGroup: {}, // 选中的团
    isTakePartIn: false, // 是否是参加别人的拼团
    choicId: -1, // 选中的型号id
    showComment: false,
    showPon: false,
    showOp: false,
    showGroup: false,
    sureGroup: false,
    show_active: false,
    is_yzc: 0, // 判断是否是yzc商品
    startTime: '', // 秒杀开始时间
    endTime: '', // 秒杀结束时间
    isStart: true, // 秒杀是否开始
    isOver: true, // 秒杀是否结束
    collectId: '', // 收藏id
    isSeller: false,
    choicPrice: '', // 选择的型号价格
    buyAlone: false, // 单独购买
    offon: 0
  },

  onLoad: function(options) {
    this.setData({
      options: options
    })
    console.log(options)
    if (options.data != undefined && options.data != 0) {
      var optionss = JSON.parse(options.data)
      console.log(options)
      getApp().globalData.uniq_openid = optionss.uniq_openid
      wx.setStorageSync('token__', optionss.token)
      wx.setStorageSync('token_key', optionss.token_key)
      service_common.fetchData(
        service_common.getUrl("user.getUserMpInfo"), {
          openid: optionss.openid,

        },
        (res) => {
          if (res.data.code == 0) {
            wx.setStorageSync('userInfo', res.data.data);
            console.log('+++++++++++++++++++++++++++++++')
            console.log(wx.getStorageSync('userInfo'))
            getApp().globalData.userInfo = res.data.data
            getApp().globalData.openid = res.data.data.openid
            getApp().globalData.unionid = res.data.data.unionid
            this.setData({
              goods_id: options.goods_id,
              offon: 1
            })
            this.getShop_uid(() => {
              api.ajax(service.url('getConstShopUser'), {}, res => {
                wx.setStorageSync('out_user_id', res.data.shop_user_id)
                this.shopGetUserShopInfo(res.data.shop_user_id);
                this.getShopInfo(res.data.shop_user_id)
              })
            })
            // 获取分享id
            if (options.share_user_id) {
              wx.setStorageSync('share_user_id', options.share_user_id)
            } else if (wx.getStorageSync('share_user_id')) {
              wx.setStorageSync('share_user_id', wx.getStorageSync('share_user_id'))
            } else {
              wx.setStorageSync('share_user_id', '')
            }
            this.check()
          }
        },
        "GET"
      )
    } else {
      if (options.goods_id) {
        this.setData({
          goods_id: options.goods_id
        })
      } else {
        api.toast('获取商品id失败')
      }

      // 判断是否是yzc商品
      if (options.is_yzc) {
        this.setData({
          is_yzc: options.is_yzc
        })
      }

      // 判断是否是商家预览商品
      if (options.is_seller) {
        this.setData({
          isSeller: true
        })
      }

      // 获取分享id
      if (options.share_user_id) {
        wx.setStorageSync('share_user_id', options.share_user_id)
      } else if (wx.getStorageSync('share_user_id')) {
        wx.setStorageSync('share_user_id', wx.getStorageSync('share_user_id'))
      } else {
        wx.setStorageSync('share_user_id', '')
      }
      this.check()
    }

  },
  // 获取店铺信息
  getShopInfo: function(shop_user_id) {
    let that = this
    let url = service.url('getShopDetail')
    api.ajax(url, {
      userid: shop_user_id
    }, function(res) {
      console.log(res);
      if (res.code == 0) {
        wx.setStorage({
          key: 'shopInfo',
          data: res.data
        })
      } else {
        api.toast(res.message)
      }
    })
  },
  shopGetUserShopInfo: function(out_user_id) {
    api.ajax(service.url('getUserShopInfo'), {
      userid: out_user_id
    }, function(res) {
      wx.setStorageSync('shop_data_shop', res.data);
    })
  },
  // 获取店铺的unid
  getShop_uid: function(cb) {
    console.log(getApp().globalData.userInfo)
    api.ajax(service.url('getShop_enter'), {
        userid: getApp().globalData.userInfo.id
      },
      function(res) {
        if (res.code == 0) {
          wx.setStorageSync("shop_data", res.data)
          cb()
        } else {
          api.toast(res.message)
        }
      })
  },
  // 检测授权
  check: function() {
    let that = this
    this.setData({
      userInfo: wx.getStorageSync('shop_data')
    })
    if (wx.getStorageSync('share_user_id')) {
      that.setShareInfo()
    }
    that.init()
  },

  // 设置分享信息
  setShareInfo: function() {
    let that = this
    let share_id = wx.getStorageSync('share_user_id')
    api.ajax(service.url('setShareUser'), {
      share_user_id: share_id,
      current_user_id: that.data.userInfo.customer_id
    }, function(res) {
      console.log(res)
    })
  },

  // 添加足迹
  addStep: function() {
    let that = this
    api.ajax(service.url('addUserStep'), {
      goods_id: that.data.goods_id,
    }, function(res) {
      console.log(res)
    })
  },

  init: function() {
    let that = this
    if (this.data.is_yzc) {
      this.getYzcGoodsInfo(function() {
        that.getGoodsComment()
        that.getChoicPirce()
        that.addStep()
      })
    } else {
      this.getGoodsInfo(function() {
        that.getGoodsComment()
        that.getChoicPirce()
        that.addStep()
      })
    }
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {
    console.log("======================")
    console.log(this.data.offon)
    if (this.data.offon == 1) {
      wx.reLaunch({
        url: '/pages/index/index',
      })
    }
  },
  // 获取商品信息
  getGoodsInfo: function(cb) {
    let that = this
    api.ajax(service.url('goodsGet'), {
        unionid: that.data.userInfo.shop_unionid,
        goods_id: that.data.goods_id
      },
      function(res) {
        if (res.code == 0) {
          let goodsInfo = res.data
          goodsInfo.is_yzc = that.data.is_yzc
          that.setData({
            goodsInfo: goodsInfo,
            endTime: res.data.date_end,
            startTime: res.data.date_start,
            collectId: res.data.collect_id
          })
          if (res.data.tag == 1) {
            that.getLowKillPrice()
            that.getTopKillPrice()
            // 秒杀商品处理
            if ((new Date(that.data.startTime)) >= (new Date())) {
              // 秒杀未开始
              that.setData({
                isStart: false,
                isOver: false
              })
            } else {
              // 开始秒杀
              that.setData({
                isStart: true
              })
              var endTime = that.data.endTime.split('-').join('/')
              if ((new Date(endTime)) <= (new Date())) {
                that.setData({
                  isOver: true
                })
              } else {
                that.setData({
                  isOver: false
                })
              }
            }
          }
          that.getLowPrice()
          that.getTopPrice()

          that.getLowMarkPrice()
          that.getTopMarkPrice()

          WxParse.wxParse('article', 'html', res.data.description, that, 5)
          cb()
        } else {
          wx.showModal({
            title: '提示',
            content: '该商品已下架或者已被商家删除',
            showCancel: false,
            success: function(rel) {
              if (rel.confirm) {
                wx.navigateBack({
                  delta: -1
                });
              }
            }
          })
        }
      })
  },

  getYzcGoodsInfo: function(cb) {
    let that = this
    api.ajax(service.url('yzcDetail'), {
        unionid: that.data.userInfo.shop_unionid,
        goods_id: that.data.goods_id
      },
      function(res) {
        if (res.code == 0) {
          let goodsInfo = res.data
          goodsInfo.is_yzc = that.data.is_yzc
          that.setData({
            goodsInfo: goodsInfo,
            endTime: res.data.date_end,
            startTime: res.data.date_start,
            collectId: res.data.collect_id
          })
          if (res.data.tag == 1) {
            that.getLowKillPrice()
            that.getTopKillPrice()
            // 秒杀商品处理
            if ((new Date(that.data.startTime)) > (new Date())) {
              // 秒杀未开始
              that.setData({
                isStart: false,
                isOver: false
              })
            } else {
              // 开始秒杀
              that.setData({
                isStart: true
              })
              var endTime = that.data.endTime.split('-').join('/')
              if ((new Date(endTime)) < (new Date())) {
                that.setData({
                  isOver: true
                })
              }
            }
          }
          that.getLowPrice()
          that.getTopPrice()

          that.getLowMarkPrice()
          that.getTopMarkPrice()

          WxParse.wxParse('article', 'html', res.data.description, that, 5)
          cb()
        } else {
          api.toast(res.message)
        }
      })
  },

  // 获取商品评论
  getGoodsComment: function() {
    let that = this
    let shop_token = wx.getStorageSync('shop_data').token;
    let shop_token_key = wx.getStorageSync('shop_data').token_key;

    api.ajax(service.url('goodsComment'), {
        unionid: wx.getStorageSync('shop_data').shop_unionid,
        token: shop_token,
        token_key: shop_token_key,
        goods_id: that.data.goods_id,
        page: that.data.page
      },
      function(res) {
        if (res.code == 0) {
          if (res.data.length > 0) {
            for (var i = 0, len = res.data.length; i < len; i++) {
              that.data.goodsComment.push(res.data[i])
            }
            that.setData({
              goodsComment: that.data.goodsComment,
              hasMoreComment: true
            })
          } else {
            that.setData({
              hasMoreComment: false
            })
          }
        } else {
          api.toast(res.message)
        }
      })
  },

  // 获取最低价
  getLowPrice: function() {
    if (this.data.is_yzc) {
      let option = this.data.goodsInfo.goods_options
      let min = option[0].yzc
      for (var i = 0, len = option.length; i < len; i++) {
        if (option[i].yzc <= min) {
          min = option[i].yzc
        }
      }
      this.setData({
        lowPrice: min
      })
    } else {
      if (this.data.goodsInfo.group_booking) {
        let option = this.data.goodsInfo.goods_options
        let min = option[0].group_price
        for (var i = 0, len = option.length; i < len; i++) {
          if (option[i].group_price <= min) {
            min = option[i].group_price
          }
        }
        this.setData({
          lowPrice: min
        })
      } else {
        let option = this.data.goodsInfo.goods_options
        let min = option[0].sale_price
        for (var i = 0, len = option.length; i < len; i++) {
          if (option[i].sale_price <= min) {
            min = option[i].sale_price
          }
        }
        this.setData({
          lowPrice: min
        })
      }
    }
  },

  // 获取最高价格
  getTopPrice: function() {
    let option = this.data.goodsInfo.goods_options
    if (this.data.is_yzc) {
      let min = option[0].yzc
      for (var i = 0, len = option.length; i < len; i++) {
        if (option[i].yzc >= min) {
          min = option[i].yzc
        }
      }
      this.setData({
        topPrice: min
      })
    } else {
      if (this.data.goodsInfo.group_booking) {
        let min = option[0].group_price
        for (var i = 0, len = option.length; i < len; i++) {
          if (option[i].group_price >= min) {
            min = option[i].group_price
          }
        }
        this.setData({
          topPrice: min
        })
      } else {
        let min = option[0].sale_price
        for (var i = 0, len = option.length; i < len; i++) {
          if (option[i].sale_price >= min) {
            min = option[i].sale_price
          }
        }
        this.setData({
          topPrice: min
        })
      }

    }
  },

  // 获取最低秒杀价
  getLowKillPrice: function() {
    let option = this.data.goodsInfo.goods_options
    let min = option[0].kill_price
    for (var i = 0, len = option.length; i < len; i++) {
      if (option[i].kill_price < min) {
        min = option[i].kill_price
      }
    }
    this.setData({
      lowKillPrice: min
    })
  },

  // 获取最高秒杀价
  getTopKillPrice: function() {
    let option = this.data.goodsInfo.goods_options
    let min = option[0].kill_price
    for (var i = 0, len = option.length; i < len; i++) {
      if (option[i].kill_price > min) {
        min = option[i].kill_price
      }
    }
    this.setData({
      topKillPrice: min
    })
  },

  // 获取最低市场价 topMarkPrice
  getLowMarkPrice: function() {
    let option = this.data.goodsInfo.goods_options
    let min = option[0].market_price
    for (var i = 0, len = option.length; i < len; i++) {
      if (option[i].market_price < min) {
        min = option[i].market_price
      }
    }
    this.setData({
      lowMarkPrice: min
    })
  },
  // 获取最低市场价 topMarkPrice
  getTopMarkPrice: function() {
    let option = this.data.goodsInfo.goods_options
    let min = option[0].market_price
    for (var i = 0, len = option.length; i < len; i++) {
      if (option[i].market_price > min) {
        min = option[i].market_price
      }
    }
    this.setData({
      topMarkPrice: min
    })
  },


  // 选择商品型号
  choicOption: function(e) {
    var ids = e.currentTarget.dataset.id
    var choic = this.data.goodsInfo.goods_options[ids]
    this.setData({
      choicId: ids,
      choicOption: choic
    })
    this.getChoicPirce()
  },

  // 立即购买、发起拼团、开启秒杀提醒
  buyNow: function() {
    // 获取系统配置，是否可以购买
    service_common.fetchData(
      
      service_common.getUrl("user.sysconfig"), {
        openid: getApp().globalData.userInfo.openid
      },
      (res) => {
        console.log(res)
        if (res.data.code == 0) {
          if (res.data.data.buy_goods == 1) { //可以购买
            let that = this
            let choicOption = this.data.choicOption
            let goodsInfo = this.data.goodsInfo
            this.setData({
              buyAlone: false
            })
            this.getChoicPirce()
            this.setData({
              isTakePartIn: false
            })
            // 开启秒杀提醒
            if (goodsInfo.tag == 1 && !this.data.isStart) {
              api.ajax(service.url('goodsRemind'), {
                  unionid: that.data.userInfo.shop_unionid,
                  goods_id: that.data.goods_id,
                  remind_type: 1
                },
                function(res) {
                  if (res.code == 0) {
                    api.toast('已开启秒杀提醒，请注意有张vipAPP推送内容')
                    let goodsInfo = that.data.goodsInfo
                    goodsInfo.is_remind = 1
                    that.setData({
                      goodsInfo: goodsInfo
                    })
                  } else {
                    api.toast(res.message)
                  }
                })
              return
            }

            // 选择型号、购买
            if (!choicOption) {
              api.toast('请选择商品型号')
              this.showOption()
            } else {
              let optionId = choicOption.id
              let quantity = this.data.num
              if (!goodsInfo.is_yzc && !goodsInfo.group_booking) {
                let str = optionId + ',' + quantity + ',0,0'
                wx.navigateTo({
                  url: `../confirm_order/confirm_order?options=${str}`,
                })
              } else if (goodsInfo.is_yzc) {
                let str = optionId + ',' + quantity
                wx.navigateTo({
                  url: `../confirm_order/confirm_order?options=${str}&is_yzc=1`,
                })
              } else if (goodsInfo.group_booking) {
                let str = optionId + ',' + quantity + ',1,0'
                wx.navigateTo({
                  url: `../confirm_order/confirm_order?options=${str}`,
                })
              }
            }
          } else {
            wx.showToast({
              icon: 'none',
              title: '请资讯分享者进行购买',
              duration: 2000
            })
          }
        }
      },
      "GET"
    )

  },

  // 添加到购物车、单独购买
  addToCart: function() {
    let that = this
    let choicOption = this.data.choicOption
    let goodsInfo = this.data.goodsInfo
    this.setData({
      buyAlone: true
    })
    this.getChoicPirce()
    if (!choicOption) {
      api.toast('请选择商品型号')
      this.showOption()
    } else {
      if (!goodsInfo.is_yzc && !goodsInfo.group_booking) {
        // 加入购物车 -- 普通商品
        let optionId = choicOption.id
        let quantity = this.data.num
        let str = optionId + ',' + quantity + ',0,0'

        api.ajax(service.url('addOrUpdate'), {
            unionid: that.data.userInfo.shop_unionid,
            goods_id: that.data.goods_id,
            option_id: optionId,
            quantity: quantity
          },
          function(res) {
            if (res.code == 0) {
              api.toast('添加成功')
            } else {
              api.toast(res.message)
            }
          })
        this.setData({
          buyAlone: false
        })
      } else if (goodsInfo.group_booking) {
        service_common.fetchData(
          service_common.getUrl("user.sysconfig"), {
            openid: getApp().globalData.userInfo.openid
          },
          (res) => {
            console.log(res)
            if (res.data.code == 0) {
              // 单独购买 -- 拼团商品
              if (res.data.data.buy_goods==1){
                let optionId = choicOption.id
                let quantity = this.data.num
                let str = optionId + ',' + quantity + ',0,0'
                wx.navigateTo({
                  url: `../confirm_order/confirm_order?options=${str}`,
                })
              }else{
                wx.showToast({
                  icon: 'none',
                  title: '请资讯分享者进行购买',
                  duration: 2000
                })
              }
              
            }
          })
      }
    }
  },

  // 收藏商品
  addToFavorite: function(e) {
    let that = this
    let id = e.currentTarget.dataset.id
    let url = service.url('addToFavorite') // 添加收藏
    let arg
    if (id) {
      // 取消收藏
      url = service.url('cancelCollect')
      arg = {
        type: 1,
        unionid: that.data.userInfo.shop_unionid,
        favorite_id: id
      }
    } else {
      // 添加收藏
      arg = {
        unionid: that.data.userInfo.shop_unionid,
        goods_id: that.data.goods_id,
        type: 1
      }
    }
    api.ajax(url, arg, function(res) {
      if (res.code == 0) {
        if (res.data.length == 0) {
          that.setData({
            collectId: 0
          })
        } else {
          that.setData({
            collectId: res.data
          })
        }
      } else {
        api.toast(res.message)
      }
    })
  },

  // 切换底部信息
  setichNav: function() {
    var status = !this.data.showComment
    this.setData({
      showComment: status,
      page: 1
    })
  },

  // 减少购买数量
  reduceNum: function() {
    let option = this.data.choicOption
    if (!option) {
      api.toast('请先选择型号')
      return
    }
    if (this.data.num > 1) {
      let num = this.data.num -= 1
      this.setData({
        num: num
      })
    }
  },

  // 增加购买数量
  addNum: function() {
    let option = this.data.choicOption
    if (!option) {
      api.toast('请先选择型号')
      return
    }
    let num = this.data.num += 1
    if (num > option.stock) {
      api.toast('库存不足啦')
      this.setData({
        num: option.stock
      })
      return
    }
    this.setData({
      num: num
    })
  },

  // 监听输入事件
  changeNum: function(e) {
    let option = this.data.choicOption
    if (!option) {
      api.toast('请先选择型号')
      this.setData({
        num: 1
      })
      return
    }
    var num = parseInt(e.detail.value)
    if (num < 1) {
      num = 1
    }
    if (num > option.stock) {
      api.toast('库存不足啦')
      this.setData({
        num: option.stock
      })
      return
    }
    this.setData({
      num: num
    })
  },

  // 前往别的商品详情
  toOtherGoods: function(e) {
    var goods_id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: `../goods_detail/goods_detail?goods_id=${goods_id}`,
    })
  },

  // 参与拼团
  takepartin: function(e) {
    let that = this
    let group_id = e.currentTarget.dataset.id
    let idx = e.currentTarget.dataset.index
    let num = this.data.goodsInfo.group_list[idx].less_group_num
    let str = '该团还差' + num + '人成团'
    if (num == 0) {
      str = '该团已满人'
    }
    wx.showModal({
      title: '提示',
      content: str,
      success: (res) => {
        if (res.confirm) {
          if (num == 0) {
            return
          }
          that.setData({
            sureGroup: true,
            showGroup: false,
            isTakePartIn: true,
            choicGroup: that.data.goodsInfo.group_list[idx]
          })
        }
      }
    })
  },

  // 确定参与拼团
  sureTakePartInt: function() {
    service_common.fetchData(
      service_common.getUrl("user.sysconfig"), {
        openid: getApp().globalData.userInfo.openid
      },
      (res) => {
        console.log(res)
        if (res.data.code == 0) {
          if (res.data.data.buy_goods == 1){
            let choicOption = this.data.choicOption
            if (!choicOption) {
              this.showOption()
              this.setData({
                sureGroup: false
              })
              api.toast('请选择商品型号')
            } else {
              let optionId = choicOption.id
              let quantity = this.data.num
              let group_id = this.data.choicGroup.group_id
              let str = optionId + ',' + quantity + ',1,0'
              if (this.data.isTakePartIn) {
                str = optionId + ',' + quantity + ',1,' + group_id;
              }
              if (this.data.buyAlone) {
                str = optionId + ',' + quantity + ',0,0'
              }
              wx.navigateTo({
                url: `../confirm_order/confirm_order?options=${str}`,
              })
            }
          }else{
            wx.showToast({
              icon: 'none',
              title: '请资讯分享者进行购买',
              duration: 2000
            })
          }
        }
      })
   
  },

  // 联系客服
  contact: function() {
    wx.showModal({
      title: '提示',
      content: '下载APP更方便联系客服',
      confirmText: '下载',
      success: (res) => {
        if (res.confirm) {
          wx.navigateTo({
            url: '../download_app/download_app',
          })
        }
      }
    })
  },

  // 返回店铺首页
  toShop: function(e) {
    let out_user_id = e.currentTarget.dataset.id
    if (this.data.offon == 1) {
      wx.reLaunch({
        url: '/pages/index/index',
      })
    } else {
      wx.reLaunch({
        url: '/pages/shop_index/shop_index?out_user_id=' + out_user_id,
      })
    }

  },

  // 显示隐藏弹层
  showPon: function() {
    this.setData({
      showPon: true
    })
  },
  hidePon: function() {
    this.setData({
      showPon: false
    })
  },
  showOption: function() {
    this.setData({
      showOp: true
    })
  },
  hideOption: function() {
    this.setData({
      showOp: false
    })
  },
  hideGroup: function() {
    this.setData({
      showGroup: false
    })
  },
  showGroup: function() {
    if (this.data.goodsInfo.group_list.length <= 0) {
      api.toast('暂无拼团')
      return
    }
    this.setData({
      showGroup: true
    })
  },
  hideSure: function() {
    this.setData({
      sureGroup: false
    })
  },

  hideActive: function() {
    this.setData({
      show_active: false
    })
  },
  showActive: function() {
    this.setData({
      show_active: true
    })
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    let type = this.data.navIndex
    let page = this.data.page += 1
    this.setData({
      page: page
    })
    if (this.data.showComment) {
      if (this.data.hasMoreComment) {
        this.getGoodsComment()
      }
    }
  },

  // 生成海报
  createImg: function() {
    let goods_id = this.data.goodsInfo.goods_id
    wx.previewImage({
      urls: [`${service.url('createImage')}?goods_id=${goods_id}&type=app&version=0.0.1`],
    })
    this.setData({
      show_active: false
    })
  },

  // 查看大图
  seeBigImg: function(e) {
    let url = e.currentTarget.dataset.url
    let arr = []
    for (var i = 0, len = this.data.goodsInfo.goods_images.length; i < len; i++) {
      arr.push(this.data.goodsInfo.goods_images[i].url)
    }
    wx.previewImage({
      current: url,
      urls: arr,
    })
  },

  // 获取选择型号的价格
  getChoicPirce: function() {
    let price = ''
    if (this.data.choicOption) { // 已选择型号
      if (this.data.goodsInfo.tag == 1) { // 秒杀商品
        if (this.data.isOver) { // 秒杀已结束
          if (this.data.goodsInfo.group_booking) { // 拼团商品
            if (this.data.buyAlone) {
              price = this.data.choicOption.sale_price
            } else {
              price = this.data.choicOption.group_price
            }
          } else {
            price = this.data.choicOption.sale_price
          }
        } else { // 秒杀未结束
          price = this.data.choicOption.kill_price
        }
      } else { // 非秒杀商品
        if (this.data.goodsInfo.group_booking) {
          if (this.data.buyAlone) {
            price = this.data.choicOption.sale_price
          } else {
            price = this.data.choicOption.group_price
          }
        } else {
          price = this.data.choicOption.sale_price
        }
      }
    } else { // 未选择型号 默认返回数据第一个型号价格
      if (this.data.goodsInfo.tag == 1) { // 秒杀商品
        if (this.data.isOver) { // 秒杀已结束
          if (this.data.goodsInfo.group_booking) { // 拼团商品
            if (this.data.buyAlone) { // 单独购买
              price = this.data.goodsInfo.goods_options[0].kill_price
            } else {
              price = this.data.goodsInfo.goods_options[0].group_price
            }
          } else { // 非拼团商品
            price = this.data.goodsInfo.goods_options[0].sale_price
          }
        } else { // 秒杀未结束
          price = this.data.goodsInfo.goods_options[0].kill_price
        }
      } else { // 非秒杀商品
        if (this.data.goodsInfo.group_booking) { // 拼团商品
          if (this.data.buyAlone)　 { // 单独购买
            price = this.data.goodsInfo.goods_options[0].sale_price
          } else {
            price = this.data.goodsInfo.goods_options[0].group_price
          }
        } else { // 非拼团商品
          price = this.data.goodsInfo.goods_options[0].sale_price
        }
      }
    }
    this.setData({
      choicPrice: price
    })
  },

  // 查看型号大图
  showBigImages: function(e) {
    let url = e.currentTarget.dataset.url
    wx.previewImage({
      current: url,
      urls: [url],
    })
  },

  showCommentImg: function(e) {
    let url = e.currentTarget.dataset.url
    let img_arr = e.currentTarget.dataset.arr
    wx.previewImage({
      current: url,
      urls: img_arr,
    })
  },

  onShareAppMessage: function() {
    let that = this
    return {
      title: that.data.goodsInfo.name,
      path: `pages/auth/auth?webUrl=goods_detail&zf_openid=${getApp().globalData.userInfo.openid}&goods_id=${that.data.goodsInfo.goods_id}&share_user_id=${that.data.userInfo.out_user_id}`
    }
  }
})